package com.zmn.plat.services.impl.product;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import com.zmn.common.dto.StatusDTO;
import com.zmn.plat.model.entity.product.ServTariffProductRelation;
import com.zmn.plat.model.entity.product.ServTariffProductRelationQuery;
import com.zmn.plat.model.vo.product.relation.ServTariffProductRelationVO;
import com.zmn.plat.persistence.interfaces.product.ServTariffProductRelationDAO;
import com.zmn.plat.services.interfaces.product.ServTariffProductRelationService;

/**
 * @author tanbiao
 * @description 产品关联关系
 * @since 2019/9/20 11:46
 * @modifier
 **/
@Service
public class ServTariffProductRelationServiceImpl implements ServTariffProductRelationService {
    @Resource
    ServTariffProductRelationDAO servTariffProductRelationDAO;

    @Override
    public ServTariffProductRelation findByProductId(Integer productId) {
        ServTariffProductRelationQuery relationQuery = new ServTariffProductRelationQuery();
        relationQuery.setProductId(productId);
        List<ServTariffProductRelation> relations = listByQuery(relationQuery);
        if (!CollectionUtils.isEmpty(relations)) {
            return relations.get(0);
        }
        return null;
    }

    @Override
    public List<ServTariffProductRelation> listPageByQuery(ServTariffProductRelationQuery query) {
        return servTariffProductRelationDAO.listPageByQuery(query);
    }

    @Override
    public List<ServTariffProductRelation> listByQuery(ServTariffProductRelationQuery query) {
        return servTariffProductRelationDAO.listByQuery(query);
    }

    @Override
    public List<ServTariffProductRelationVO> listTariffProductByProductIds(List<Integer> productIds) {
        return servTariffProductRelationDAO.listTariffProductByProductIds(productIds);
    }

    @Override
    public List<ServTariffProductRelationVO> listByProductIds(List<Integer> productIds) {
        return servTariffProductRelationDAO.listByProductIds(productIds);
    }

    @Override
    public List<ServTariffProductRelationVO> listByQueryForTariff(ServTariffProductRelationQuery query) {
        return servTariffProductRelationDAO.listByQueryFowTariff(query);
    }
    @Override
    public List<Integer> listTarifProductIdsByBizType(Integer bizType) {
        return servTariffProductRelationDAO.listTarifProductIdsByBizType(bizType);
    }

    @Override
    public Integer countByQuery(ServTariffProductRelationQuery query) {
        return servTariffProductRelationDAO.countByQuery(query);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer updateByKey(ServTariffProductRelation query) {
        return servTariffProductRelationDAO.updateByKey(query);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer updateBatch(ServTariffProductRelation relation, List<Integer> exitsProductIds) {
        return servTariffProductRelationDAO.updateBatch(relation, exitsProductIds);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer updateStatusBatch(List<Integer> arrayIds, int status, String mcStaffName) {
        StatusDTO dto = new StatusDTO();
        dto.setIds(arrayIds);
        dto.setStatus(status);
        dto.setUpdater(mcStaffName);
        return servTariffProductRelationDAO.updateStatusBatch(dto);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer insert(ServTariffProductRelation relation) {
        return servTariffProductRelationDAO.insert(relation);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer insertBatch(List<ServTariffProductRelation> insertRelations) {
        return servTariffProductRelationDAO.insertBatch(insertRelations);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer deleteBatch(List<Integer> ids) {
        return servTariffProductRelationDAO.deleteBatch(ids);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer deleteByProductId(Integer productId) {
        return servTariffProductRelationDAO.deleteByProductId(productId);
    }

}
